﻿using Prism.Commands;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using WPF_RoleManager_Demo.Models;
using WPF_RoleManager_Demo.Service;

namespace WPF_RoleManager_Demo.ViewModels
{

    internal class MainWindowViewModel : ReactiveObject
    {
        private readonly PermissionManager _permissionManager;
        public ICommand AdminCommand { get; private set; }
        public ICommand UserCommand { get; private set; }

        public MainWindowViewModel(User currentUser)
        {
            _permissionManager = new PermissionManager(currentUser);
            InitializeCommands();
        }

        private void InitializeCommands()
        {
            AdminCommand = new DelegateCommand(ExecuteAdminCommand, CanExecuteAdminCommand);
            UserCommand = new DelegateCommand(ExecuteUserCommand, CanExecuteUserCommand);
        }

        private void ExecuteAdminCommand()
        {
            MessageBox.Show("这是管理员权限。");
        }

        private bool CanExecuteAdminCommand()
        {
            return _permissionManager.HasPermission(UserRole.Admin);
        }

        private void ExecuteUserCommand()
        {
            MessageBox.Show("这是用户权限。");
        }

        private bool CanExecuteUserCommand()
        {
            return _permissionManager.HasPermission(UserRole.User) || _permissionManager.HasPermission(UserRole.Admin);
        }
    }
}
